# Carbon Jiao <http://archlive-pkg.googlecode.com>

# 工具链编译顺序: kernel-headers->glibc->binutils->gcc-libs->gcc->binutils->glibc

pkgname=glibc
# 软件名仍然用glibc为了解决依赖问题
_realpkgname=glibc
pkgver=2.10.1
pkgrel=4
_glibcdate=20090511
install=glibc.install
backup=(etc/locale.gen etc/nscd.conf)
pkgdesc="GNU C Library Mini版本，只加入了中文的支持"
arch=('i686' 'x86_64')
license=('GPL' 'LGPL')
url="http://www.gnu.org/software/libc"
groups=('base')
provides=('glibc')
conflicts=('glibc')
depends=('kernel-headers>=2.6.30.1' 'tzdata')
makedepends=('gcc>=4.4')
replaces=('glibc-xen')
source=(ftp://ftp.archlinux.org/other/glibc/${_realpkgname}-${pkgver}_${_glibcdate}.tar.bz2
	glibc-2.10-dont-build.patch
	glibc-2.10-bz4781.patch
	nscd
	locale-gen
	locale.gen.txt)
md5sums=(7a34595abeeedb9aab758aa51d09ed88
	870dbdf19efca776cfce7b64e417e52e
	0c5540efc51c0b93996c51b57a8540ae
	b587ee3a70c9b3713099295609afde49
	476e9113489f93b348b21e144b6a8fcf
	994a6ccddcee58a2d8f4e62024b05146
)

build() {

  cd ${srcdir}/glibc

  # timezone data is in separate package (tzdata)
   # 补丁修改，删除了localedata的编译，以免全部语言支持都加入
  patch -Np1 -i ${srcdir}/glibc-2.10-dont-build.patch || return 1

  # http://sources.redhat.com/bugzilla/show_bug.cgi?id=4781
  patch -Np1 -i ${srcdir}/glibc-2.10-bz4781.patch || return 1

  install -dm755 ${pkgdir}/etc
  touch ${pkgdir}/etc/ld.so.conf

  mkdir glibc-build
  cd glibc-build

  if [ "${CARCH}" = "i686" ]; then
    # Hack to fix NPTL issues with Xen, only required on 32bit platforms
    export CFLAGS="${CFLAGS} -mno-tls-direct-seg-refs"
  fi

  echo "slibdir=/lib" >> configparms

  ../configure --prefix=/usr \
      --enable-add-ons=nptl,libidn --without-cvs \
      --enable-kernel=2.6.0 --disable-profile \
      --with-headers=/usr/include --libexecdir=/usr/lib \
      --enable-bind-now --with-tls --with-__thread \
      --libdir=/usr/lib --without-selinux
        
  make || return 1
  make install_root=${pkgdir} install || return 1

  rm -f ${pkgdir}/etc/ld.so.cache ${pkgdir}/etc/ld.so.conf ${pkgdir}/etc/localtime

  install -dm755 ${pkgdir}/etc/rc.d
  install -dm755 ${pkgdir}/usr/sbin
  install -dm755 ${pkgdir}/usr/lib/locale
  install -m644 ${srcdir}/glibc/nscd/nscd.conf ${pkgdir}/etc/nscd.conf
  install -m755 ${srcdir}/nscd ${pkgdir}/etc/rc.d/nscd
  install -m755 ${srcdir}/locale-gen ${pkgdir}/usr/sbin

  sed -i -e 's/^\tserver-user/#\tserver-user/' ${pkgdir}/etc/nscd.conf || return 1

  # create /etc/locale.gen  内置中文支持，无需此文件
  install -m644 ${srcdir}/locale.gen.txt ${pkgdir}/etc/locale.gen

  if [ "${CARCH}" = "x86_64" ]; then
    # fix for the linker
    sed -i '/RTLDLIST/s%/ld-linux.so.2 /lib64%%' ${pkgdir}/usr/bin/ldd
    #Comply with multilib binaries, they look for the linker in /lib64
    mkdir ${pkgdir}/lib64
    cd ${pkgdir}/lib64
    ln -v -s ../lib/ld* .
  fi

  #删除多余文件——常规运行不需要，编译需要完全版
  cat "$startdir/del.list" | grep -v "^#" | while read file; do [ -f $pkgdir/$file ] && (rm -f $pkgdir/$file); done

   # 加入中文支持
  LOCALEDEF=$pkgdir/usr/bin/localedef
  locales_dir=$srcdir/glibc/localedata
  $LOCALEDEF -i ${locales_dir}/locales/zh_CN -f ${locales_dir}/charmaps/GB18030 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_CN -f ${locales_dir}/charmaps/GBK -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_CN -f ${locales_dir}/charmaps/UTF-8 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_CN -f ${locales_dir}/charmaps/GB2312 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_CN -f ${locales_dir}/charmaps/GB18030 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_HK -f ${locales_dir}/charmaps/UTF-8 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_HK -f ${locales_dir}/charmaps/BIG5-HKSCS -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_TW -f ${locales_dir}/charmaps/EUC-TW -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_TW -f ${locales_dir}/charmaps/UTF-8 -c --prefix=$pkgdir --add-to-archive
  $LOCALEDEF -i ${locales_dir}/locales/zh_TW -f ${locales_dir}/charmaps/BIG5 -c --prefix=$pkgdir --add-to-archive
}